module Texture {
	export class TexturePacker extends util.ILoadInterface {
		private _loadingUI:Component.LoadingUI;
		private _sprites:Array<egret.Bitmap>;

		/**
		 * 构造函数
		 */
		public constructor(){
			super();
			this.once(egret.Event.ADDED_TO_STAGE,this.onAddedToStage,this);
		}

		/**
		 * 添加到舞台
		 */
		private onAddedToStage(evt: egret.Event): void {
			this._loadingUI = new Component.LoadingUI(0, 100);
			this.addChild(this._loadingUI);
			this._loadingUI.x=this.stage.stageWidth/2;
			this._loadingUI.y=this.stage.stageHeight/2;
			var loadUtil:util.LoadGroupUtil=util.LoadGroupUtil.getInstance(this._loadingUI);
			loadUtil.preLoadGroup(this,"resource/default.res.json","sheet","resource/");
		}

		/**
		 * @override
		 * 资源组加载完成回调
		 */
		public loadGroupCallback():void{
			this.removeChild(this._loadingUI);
			this._sprites=new Array<egret.Bitmap>();
			var sp:egret.Bitmap=new egret.Bitmap(RES.getRes("1_json.sprite1"));
			this.addChild(sp);
			this._sprites.push(sp);
			sp=new egret.Bitmap(RES.getRes("1_json.sprite2"));
			this.addChild(sp);
			this._sprites.push(sp);
			this.setPositions();
		}

		/**
		 * 随机设置精灵位置
		 */
		public setPositions():void{
			for(var i:number=this._sprites.length-1;i>-1;i--){
				this._sprites[i].x=(this.stage.stageWidth-this._sprites[i].width/2)*Math.random();
				this._sprites[i].y=120+(this.stage.stageHeight-this._sprites[i].height/2-120)*Math.random();
			}
		}
	}
}